package www.dianbaozu.com.ui.server

import android.widget.TextView
import androidx.core.view.isVisible
import com.chad.library.adapter.base.entity.node.BaseNode
import com.chad.library.adapter.base.provider.BaseNodeProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.netease.nim.uikit.api.NIMHelper
import www.dianbaozu.com.R
import www.wen.com.common.lib.data.entities.ServerGroupEntity
import www.wen.com.common.lib.extension.unread

/**
 * @author WEN
 * @Description:
 * @date 2021/9/16 12:09
 */
class ServerListSecondProvider: BaseNodeProvider() {

    override val itemViewType: Int
        get() = 2

    override val layoutId: Int
        get() = R.layout.item_server_list_scend_provider

    override fun convert(helper: BaseViewHolder, item: BaseNode) {
        val entity = item as ServerGroupEntity.Content.ChannelVO
        if (entity.unreadCount == null) {
            entity.unreadCount = NIMHelper.teamUnreadCountMap[item.teamId]
        }
        helper.setText(R.id.tvUnreadMessage,entity.unreadCount?.unread()?:"0")
        helper.getView<TextView>(R.id.slUnreadMessage).isVisible = entity.unreadCount?:0 > 0
        helper.setText(R.id.tvServerName,entity.channelName)
    }

}